package com.assjirc.commands;

import com.assjirc.annotations.Command;
import com.assjirc.frames.GUI;

@Command("server")
public class Server implements Executable {

	@Override
	public void execute(String params, GUI gui) {
		if (params == null || params.equals("") || !params.contains(" ")) {
			gui.getErrorLabel().setText("not enough params");
		} else {
			String[] split = params.split(" ");
			if (split.length < 2) {
				gui.getErrorLabel().setText("not enough params");
			} else if (split.length > 3) {
				gui.getErrorLabel().setText("too many params");
			} else if (split.length == 2){
				gui.joinServer(split[0], split[1], null);
			} else {
				gui.joinServer(split[0], split[1], split[2]);
			}
		}
	}

	@Override
	public String getDetailedHelp(String... params) {
		return getSimpleHelp() + ", syntax: /server <server> <nick> [password]";
	}

	@Override
	public String getSimpleHelp() {
		return "attempts to join the specified server";
	}

}
